home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Open Transport / Sample Code / DTS Sample Code / Option Management Samples / SetReplyCntOptionSample.c < prev   
Encoding:
C/C++ Source or Header  |  1996-11-19  |  2.2 KB  |  75 lines  |  [TEXT/CWIE]

  1. #include <OpenTransport.h>            // open transport files            
  2. #include <OpenTptAppletalk.h>
  3.  
  4. OSStatus DoNegotiateReplyCntOption(EndpointRef ep, UInt32 replyCnt);
  5.  
  6. /*
  7.     Sample function to set the ATP_OPT_REPLYCNT option for an ATP 
  8.     endpoint.  This function can also be used by PAP endpoints prior to
  9.     connecting to a printer which replies with less than the default 8
  10.     expected reply packets, AND does not set the EOM bit in the message.
  11.     This function also demonstrates the use of the OTOptionManagement call.
  12.     
  13.     Unless explicitely defined by XTI, all Open Transport options
  14.     use a kOTFourByteOptionSize buffer.
  15.     
  16.     Input
  17.     EndpointRef ep - endpoint on which to set EOM option on
  18.     UInt32 replyCnt - expected number of replies 1 - 8
  19.  
  20.    Return: kOTNoError indicates that the option was successfully negotiated
  21.                OSStatus is an error if < 0, otherwise, the status field is
  22.                returned and is > 0.
  23.     
  24. */
  25. OSStatus DoNegotiateReplyCntOption(EndpointRef ep, UInt32 replyCnt)
  26.  
  27. {
  28.     UInt8        buf[kOTFourByteOptionSize];    // define buffer for fourByte Option size
  29.     TOption*    opt;                        // option ptr to make items easier to access
  30.     TOptMgmt    req;
  31.     TOptMgmt    ret;
  32.     OSStatus    err;
  33.     Boolean        isAsync = false;
  34.     
  35.     if ((replyCnt < 1) || (replyCnt > 8))    // preflight replyCnt
  36.         return -1;                            // return -1 (err) if replyCnt is invalid
  37.         
  38.     opt = (TOption*)buf;                    // set option ptr to buffer
  39.     req.opt.buf    = buf;
  40.     req.opt.len    = sizeof(buf);
  41.     req.flags    = T_NEGOTIATE;                // negotiate for rawmode option
  42.  
  43.     ret.opt.buf = buf;
  44.     ret.opt.maxlen = kOTFourByteOptionSize;
  45.     
  46.  
  47.     opt->level    = ATK_ATP;                    // dealing with ATP level 
  48.     opt->name    = ATP_OPT_REPLYCNT;
  49.     opt->len    = kOTFourByteOptionSize;
  50.     opt->status = 0;
  51.     *(UInt32*)opt->value = replyCnt;        // set the desired option level, true or false
  52.  
  53.     if (OTIsSynchronous(ep) == false)        // check whether ep sync or not
  54.     {
  55.         isAsync = true;                        // set flag if async
  56.         OTSetSynchronous(ep);                // set endpoint to sync    
  57.     }
  58.                 
  59.     err = OTOptionManagement(ep, &req, &ret);
  60.     
  61.     if (isAsync == true)                    // restore ep state if necessary
  62.         OTSetAsynchronous(ep);
  63.     
  64.         // if no error then return the option status value
  65.     if (err == kOTNoError)
  66.     {
  67.         if (opt->status != T_SUCCESS)
  68.             err = opt->status;
  69.         else
  70.             err = kOTNoError;
  71.     }
  72.         
  73.     return err;
  74. }
  75.